package com.sjk.flink.correct.rules;

import com.fasterxml.jackson.core.type.TypeReference;
import com.sjk.flink.correct.IfCorrectRule;
import com.sjk.flink.util.ObjectMapperUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

public class FtpUrlRuler implements IfCorrectRule {

    private static final Logger log = LoggerFactory.getLogger(FtpUrlRuler.class);

    @Override
    public String getName() {
        return "FtpUrl";
    }

    @Override
    public Object transformValue(Object val) {
        if(val!=null){
            try {
                List<Integer> userList = ObjectMapperUtil.getObjectMapper().readValue(val.toString(), new TypeReference<List<Integer>>(){});
                int bound = userList.size();
                byte[] bes = new byte[bound];
                for (int i = 0; i < bound; i++) {
                    int anInt = userList.get(i);
                    bes[i] = (byte)anInt;
                }
                return new String(bes);
            }catch (Exception ex){
                ex.printStackTrace();
            }
        }
        return null;
    }

}